home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Graphics / StScan / localop.c < prev    next >
C/C++ Source or Header  |  1997-08-11  |  13KB  |  439 lines

  1. /*
  2. **      $VER: localop.c 3.00D (11.8.97)
  3. **
  4. **      STScan local operation routines
  5. **
  6. **      Written by Frank-Christian Kruegel, Henning Peters, Andreas R. Kleinert
  7. **      GNU General Public License V2
  8. */
  9.  
  10. #include "stscan.h"
  11.  
  12. void lowpass(void)
  13. { UBYTE *picptr,*cpyptr;
  14.   ULONG x,y,cnt;
  15.   ULONG lin1ofs,lin2ofs;
  16.   UBYTE b,v;
  17.   char wtitel[64];
  18.  
  19.   SetWindowTitles(win,"Bewege",(UBYTE *)-1);
  20.   picptr=memptr+memneed;
  21.   cpyptr=picptr+(ULONG)(memwidth*2);
  22.   for (cnt=0;cnt<memneed;cnt++)
  23.     *(--cpyptr)=*(--picptr);
  24.   picptr=memptr;
  25.   cpyptr=picptr+(ULONG)(memwidth*2);
  26.   for (cnt=0;cnt<(memwidth>>1);cnt++) *(picptr++)=255;
  27.   lin1ofs=memwidth>>1;
  28.   lin2ofs=memwidth;
  29.   SetWindowTitles(win,"Verarbeite 000%",(UBYTE *)-1);
  30.   for (y=1;y<memheight-1;y++)
  31.   { b=15;
  32.     for (x=1;x<memwidth-1;x++)
  33.     { if (x&1)
  34.       { v=((*(cpyptr        )&0x0f)+(*(cpyptr+        1)>>4)+(*(cpyptr+        1)&0x0f)
  35.           +(*(cpyptr+lin1ofs)&0x0f)+(*(cpyptr+lin1ofs+1)>>4)+(*(cpyptr+lin1ofs+1)&0x0f)
  36.           +(*(cpyptr+lin2ofs)&0x0f)+(*(cpyptr+lin2ofs+1)>>4)+(*(cpyptr+lin2ofs+1)&0x0f))/9;
  37.         *(picptr++)=(b<<4)|v;
  38.         cpyptr++;
  39.       }
  40.       else
  41.       { b=((*(cpyptr        )>>4)+(*(cpyptr        )&0x0f)+(*(cpyptr+        1)>>4)
  42.           +(*(cpyptr+lin1ofs)>>4)+(*(cpyptr+lin1ofs)&0x0f)+(*(cpyptr+lin1ofs+1)>>4)
  43.           +(*(cpyptr+lin2ofs)>>4)+(*(cpyptr+lin2ofs)&0x0f)+(*(cpyptr+lin2ofs+1)>>4))/9;
  44.       }
  45.     }
  46.     *(picptr++)=(b<<4)|15;
  47.     cpyptr+=1;
  48.     if (!(y%100))
  49.     { sprintf(&wtitel[0],"Verarbeite %03d %%",y*100/memheight);
  50.       SetWindowTitles(win,&wtitel[0],(UBYTE *)-1);
  51.     }
  52.   }
  53.   for (cnt=0;cnt<(memwidth>>1);cnt++) *(picptr++)=255;
  54.   SetWindowTitles(win," ",(UBYTE *)-1);
  55. }
  56.  
  57. void highpass(void)
  58. { UBYTE *picptr,*cpyptr;
  59.   ULONG x,y,cnt;
  60.   ULONG lin1ofs,lin2ofs;
  61.   BYTE b,v;
  62.   char wtitel[64];
  63.  
  64.   SetWindowTitles(win,"Bewege",(UBYTE *)-1);
  65.   picptr=memptr+memneed;
  66.   cpyptr=picptr+(ULONG)(memwidth*2);
  67.   for (cnt=0;cnt<memneed;cnt++)
  68.     *(--cpyptr)=*(--picptr);
  69.   picptr=memptr;
  70.   cpyptr=picptr+(ULONG)(memwidth*2);
  71.   for (cnt=0;cnt<(memwidth>>1);cnt++) *(picptr++)=255;
  72.   lin1ofs=memwidth>>1;
  73.   lin2ofs=memwidth;
  74.   SetWindowTitles(win,"Verarbeite 000%",(UBYTE *)-1);
  75.   for (y=1;y<memheight-1;y++)
  76.   { b=15;
  77.     for (x=1;x<memwidth-1;x++)
  78.     { if (x&1)
  79.       { v=(-(*(cpyptr        )&0x0f)  -(*(cpyptr+        1)>>4)-(*(cpyptr+        1)&0x0f)
  80.            -(*(cpyptr+lin1ofs)&0x0f)+8*(*(cpyptr+lin1ofs+1)>>4)-(*(cpyptr+lin1ofs+1)&0x0f)
  81.            -(*(cpyptr+lin2ofs)&0x0f)  -(*(cpyptr+lin2ofs+1)>>4)-(*(cpyptr+lin2ofs+1)&0x0f));
  82.         if (v<0) v=0;
  83.         if (v>15) v=15;
  84.         *(picptr++)=(b<<4)|v;
  85.         cpyptr++;
  86.       }
  87.       else
  88.       { b=(-(*(cpyptr        )>>4)  -(*(cpyptr        )&0x0f)-(*(cpyptr+        1)>>4)
  89.            -(*(cpyptr+lin1ofs)>>4)+8*(*(cpyptr+lin1ofs)&0x0f)-(*(cpyptr+lin1ofs+1)>>4)
  90.            -(*(cpyptr+lin2ofs)>>4)  -(*(cpyptr+lin2ofs)&0x0f)-(*(cpyptr+lin2ofs+1)>>4));
  91.         if (b<0) b=0;
  92.         if (b>15) b=15;
  93.       }
  94.     }
  95.     *(picptr++)=(b<<4)|15;
  96.     cpyptr+=1;
  97.     if (!(y%100))
  98.     { sprintf(&wtitel[0],"Verarbeite %03d %%",y*100/memheight);
  99.       SetWindowTitles(win,&wtitel[0],(UBYTE *)-1);
  100.     }
  101.   }
  102.   for (cnt=0;cnt<(memwidth>>1);cnt++) *(picptr++)=255;
  103.   SetWindowTitles(win," ",(UBYTE *)-1);
  104. }
  105.  
  106. void blowpass(void)
  107. { UBYTE *picptr,*cpyptr;
  108.   ULONG x,y,cnt;
  109.   ULONG lin1ofs,lin2ofs,lin3ofs,lin4ofs;
  110.   UWORD b=0,v;
  111.   char wtitel[64];
  112.  
  113.   SetWindowTitles(win,"Bewege",(UBYTE *)-1);
  114.   picptr=memptr+memneed;
  115.   cpyptr=picptr+(ULONG)(memwidth*2);
  116.   for (cnt=0;cnt<memneed;cnt++)
  117.     *(--cpyptr)=*(--picptr);
  118.   picptr=memptr;
  119.   cpyptr=picptr+(ULONG)(memwidth*2);
  120.   for (cnt=0;cnt<memwidth;cnt++) *(picptr++)=255;
  121.   lin1ofs=memwidth>>1;
  122.   lin2ofs=2*lin1ofs;
  123.   lin3ofs=lin1ofs+lin2ofs;
  124.   lin4ofs=2*lin2ofs;
  125.   SetWindowTitles(win,"Verarbeite 000%",(UBYTE *)-1);
  126.   for (y=2;y<memheight-2;y++)
  127.   { *(picptr++)=255;
  128.     for (x=2;x<memwidth-2;x++)
  129.     { if (x&1)
  130.       { v=  (*(cpyptr          )&0x0f)
  131.            +(*(cpyptr+        1)>>4)
  132.            +(*(cpyptr+        1)&0x0f)
  133.            +(*(cpyptr+        2)>>4)
  134.            +(*(cpyptr+        2)&0x0f)
  135.          +  (*(cpyptr+lin1ofs  )&0x0f)
  136.            +(*(cpyptr+lin1ofs+1)>>4)
  137.            +(*(cpyptr+lin1ofs+1)&0x0f)
  138.            +(*(cpyptr+lin1ofs+2)>>4)
  139.            +(*(cpyptr+lin1ofs+2)&0x0f)
  140.          +  (*(cpyptr+lin2ofs  )&0x0f)
  141.            +(*(cpyptr+lin2ofs+1)>>4)
  142.            +(*(cpyptr+lin2ofs+1)&0x0f)
  143.            +(*(cpyptr+lin2ofs+2)>>4)
  144.            +(*(cpyptr+lin2ofs+2)&0x0f)
  145.          +  (*(cpyptr+lin3ofs  )&0x0f)
  146.            +(*(cpyptr+lin3ofs+1)>>4)
  147.            +(*(cpyptr+lin3ofs+1)&0x0f)
  148.            +(*(cpyptr+lin3ofs+2)>>4)
  149.            +(*(cpyptr+lin3ofs+2)&0x0f)
  150.          +  (*(cpyptr+lin4ofs  )&0x0f)
  151.            +(*(cpyptr+lin4ofs+1)>>4)
  152.            +(*(cpyptr+lin4ofs+1)&0x0f)
  153.            +(*(cpyptr+lin4ofs+2)>>4)
  154.            +(*(cpyptr+lin4ofs+2)&0x0f);
  155.         *(picptr++)=(((b/25)&0x0f)<<4)|((v/25)&0x0f);
  156.         cpyptr++;
  157.       }
  158.       else
  159.       { b=  (*(cpyptr          )>>4)
  160.            +(*(cpyptr          )&0x0f)
  161.            +(*(cpyptr+        1)>>4)
  162.            +(*(cpyptr+        1)&0x0f)
  163.            +(*(cpyptr+        2)>>4)
  164.          +  (*(cpyptr+lin1ofs  )>>4)
  165.            +(*(cpyptr+lin1ofs  )&0x0f)
  166.            +(*(cpyptr+lin1ofs+1)>>4)
  167.            +(*(cpyptr+lin1ofs+1)&0x0f)
  168.            +(*(cpyptr+lin1ofs+2)>>4)
  169.          +  (*(cpyptr+lin2ofs  )>>4)
  170.            +(*(cpyptr+lin2ofs  )&0x0f)
  171.            +(*(cpyptr+lin2ofs+1)>>4)
  172.            +(*(cpyptr+lin2ofs+1)&0x0f)
  173.            +(*(cpyptr+lin2ofs+2)>>4)
  174.          +  (*(cpyptr+lin3ofs  )>>4)
  175.            +(*(cpyptr+lin3ofs  )&0x0f)
  176.            +(*(cpyptr+lin3ofs+1)>>4)
  177.            +(*(cpyptr+lin3ofs+1)&0x0f)
  178.            +(*(cpyptr+lin3ofs+2)>>4)
  179.          +  (*(cpyptr+lin4ofs  )>>4)
  180.            +(*(cpyptr+lin4ofs  )&0x0f)
  181.            +(*(cpyptr+lin4ofs+1)>>4)
  182.            +(*(cpyptr+lin4ofs+1)&0x0f)
  183.            +(*(cpyptr+lin4ofs+2)>>4);
  184.       }
  185.     }
  186.     *(picptr++)=255;
  187.     cpyptr+=2;
  188.     if (!(y%100))
  189.     { sprintf(&wtitel[0],"Verarbeite %03d %%",y*100/memheight);
  190.       SetWindowTitles(win,&wtitel[0],(UBYTE *)-1);
  191.     }
  192.   }
  193.   for (cnt=0;cnt<memwidth;cnt++) *(picptr++)=255;
  194.   SetWindowTitles(win," ",(UBYTE *)-1);
  195. }
  196.  
  197. void relief(void)
  198. { UBYTE *picptr,*cpyptr;
  199.   ULONG x,y,cnt;
  200.   ULONG lin1ofs,lin2ofs;
  201.   BYTE b,v;
  202.   char wtitel[64];
  203.  
  204.   SetWindowTitles(win,"Bewege",(UBYTE *)-1);
  205.   picptr=memptr+memneed;
  206.   cpyptr=picptr+(ULONG)(memwidth*2);
  207.   for (cnt=0;cnt<memneed;cnt++)
  208.     *(--cpyptr)=*(--picptr);
  209.   picptr=memptr;
  210.   cpyptr=picptr+(ULONG)(memwidth*2);
  211.   for (cnt=0;cnt<(memwidth>>1);cnt++) *(picptr++)=255;
  212.   lin1ofs=memwidth>>1;
  213.   lin2ofs=memwidth;
  214.   SetWindowTitles(win,"Verarbeite 000%",(UBYTE *)-1);
  215.   for (y=1;y<memheight-1;y++)
  216.   { b=15;
  217.     for (x=1;x<memwidth-1;x++)
  218.     { if (x&1)
  219.       { v=(   (*(cpyptr        )&0x0f)   +(*(cpyptr+        1)>>4)
  220.              +(*(cpyptr+lin1ofs)&0x0f)                              -(*(cpyptr+lin1ofs+1)&0x0f)
  221.                                          -(*(cpyptr+lin2ofs+1)>>4)  -(*(cpyptr+lin2ofs+1)&0x0f))+8;
  222.         if (v<0) v=0;
  223.         if (v>15) v=15;
  224.         *(picptr++)=(b<<4)|v;
  225.         cpyptr++;
  226.       }
  227.       else
  228.       { b=(   (*(cpyptr        )>>4)   +(*(cpyptr        )&0x0f)
  229.              +(*(cpyptr+lin1ofs)>>4)                              -(*(cpyptr+lin1ofs+1)>>4)
  230.                                        -(*(cpyptr+lin2ofs)&0x0f)  -(*(cpyptr+lin2ofs+1)>>4))+8;
  231.         if (b<0) b=0;
  232.         if (b>15) b=15;
  233.       }
  234.     }
  235.     *(picptr++)=(b<<4)|15;
  236.     cpyptr+=1;
  237.     if (!(y%100))
  238.     { sprintf(&wtitel[0],"Verarbeite %03d %%",y*100/memheight);
  239.       SetWindowTitles(win,&wtitel[0],(UBYTE *)-1);
  240.     }
  241.   }
  242.   for (cnt=0;cnt<(memwidth>>1);cnt++) *(picptr++)=255;
  243.   SetWindowTitles(win," ",(UBYTE *)-1);
  244. }
  245.  
  246. void minop(void)
  247. { UBYTE *picptr,*cpyptr;
  248.   ULONG x,y,cnt;
  249.   ULONG lin1ofs,lin2ofs;
  250.   UBYTE b,v,i,p[9];
  251.   char wtitel[64];
  252.  
  253.   SetWindowTitles(win,"Bewege",(UBYTE *)-1);
  254.   picptr=memptr+memneed;
  255.   cpyptr=picptr+(ULONG)(memwidth*2);
  256.   for (cnt=0;cnt<memneed;cnt++)
  257.     *(--cpyptr)=*(--picptr);
  258.   picptr=memptr;
  259.   cpyptr=picptr+(ULONG)(memwidth*2);
  260.   for (cnt=0;cnt<(memwidth>>1);cnt++) *(picptr++)=255;
  261.   lin1ofs=memwidth>>1;
  262.   lin2ofs=memwidth;
  263.   SetWindowTitles(win,"Verarbeite 000%",(UBYTE *)-1);
  264.   for (y=1;y<memheight-1;y++)
  265.   { b=15;
  266.     for (x=1;x<memwidth-1;x++)
  267.     { if (x&1)
  268.       { p[0]=(*(cpyptr          )&0x0f);
  269.         p[1]=(*(cpyptr+        1)>>4);
  270.         p[2]=(*(cpyptr+        1)&0x0f);
  271.         p[3]=(*(cpyptr+lin1ofs  )&0x0f);
  272.         p[4]=(*(cpyptr+lin1ofs+1)>>4);
  273.         p[5]=(*(cpyptr+lin1ofs+1)&0x0f);
  274.         p[6]=(*(cpyptr+lin2ofs  )&0x0f);
  275.         p[7]=(*(cpyptr+lin2ofs+1)>>4);
  276.         p[8]=(*(cpyptr+lin2ofs+1)&0x0f);
  277.         v=15;
  278.         for (i=0;i<9;i++) if (p[i]<v) v=p[i];
  279.         *(picptr++)=(b<<4)|v;
  280.         cpyptr++;
  281.       }
  282.       else
  283.       { p[0]=(*(cpyptr          )>>4);
  284.         p[1]=(*(cpyptr          )&0x0f);
  285.         p[2]=(*(cpyptr+        1)>>4);
  286.         p[3]=(*(cpyptr+lin1ofs  )>>4);
  287.         p[4]=(*(cpyptr+lin1ofs  )&0x0f);
  288.         p[5]=(*(cpyptr+lin1ofs+1)>>4);
  289.         p[6]=(*(cpyptr+lin2ofs  )>>4);
  290.         p[7]=(*(cpyptr+lin2ofs+1)&0x0f);
  291.         p[8]=(*(cpyptr+lin2ofs+1)>>4);
  292.         b=15;
  293.         for (i=0;i<9;i++) if (p[i]<b) b=p[i];
  294.       }
  295.     }
  296.     *(picptr++)=(b<<4)|15;
  297.     cpyptr+=1;
  298.     if (!(y%100))
  299.     { sprintf(&wtitel[64],"Verarbeite %03d %%",y*100/memheight);
  300.       SetWindowTitles(win,&wtitel[0],(UBYTE *)-1);
  301.     }
  302.   }
  303.   for (cnt=0;cnt<(memwidth>>1);cnt++) *(picptr++)=255;
  304.   SetWindowTitles(win," ",(UBYTE *)-1);
  305. }
  306.  
  307. void maxop(void)
  308. { UBYTE *picptr,*cpyptr;
  309.   ULONG x,y,cnt;
  310.   ULONG lin1ofs,lin2ofs;
  311.   UBYTE b,v,i,p[9];
  312.   char wtitel[64];
  313.  
  314.   SetWindowTitles(win,"Bewege",(UBYTE *)-1);
  315.   picptr=memptr+memneed;
  316.   cpyptr=picptr+(ULONG)(memwidth*2);
  317.   for (cnt=0;cnt<memneed;cnt++)
  318.     *(--cpyptr)=*(--picptr);
  319.   picptr=memptr;
  320.   cpyptr=picptr+(ULONG)(memwidth*2);
  321.   for (cnt=0;cnt<(memwidth>>1);cnt++) *(picptr++)=255;
  322.   lin1ofs=memwidth>>1;
  323.   lin2ofs=memwidth;
  324.   SetWindowTitles(win,"Verarbeite 000%",(UBYTE *)-1);
  325.   for (y=1;y<memheight-1;y++)
  326.   { b=15;
  327.     for (x=1;x<memwidth-1;x++)
  328.     { if (x&1)
  329.       { p[0]=(*(cpyptr          )&0x0f);
  330.         p[1]=(*(cpyptr+        1)>>4);
  331.         p[2]=(*(cpyptr+        1)&0x0f);
  332.         p[3]=(*(cpyptr+lin1ofs  )&0x0f);
  333.         p[4]=(*(cpyptr+lin1ofs+1)>>4);
  334.         p[5]=(*(cpyptr+lin1ofs+1)&0x0f);
  335.         p[6]=(*(cpyptr+lin2ofs  )&0x0f);
  336.         p[7]=(*(cpyptr+lin2ofs+1)>>4);
  337.         p[8]=(*(cpyptr+lin2ofs+1)&0x0f);
  338.         v=0;
  339.         for (i=0;i<9;i++) if (p[i]>v) v=p[i];
  340.         *(picptr++)=(b<<4)|v;
  341.         cpyptr++;
  342.       }
  343.       else
  344.       { p[0]=(*(cpyptr          )>>4);
  345.         p[1]=(*(cpyptr          )&0x0f);
  346.         p[2]=(*(cpyptr+        1)>>4);
  347.         p[3]=(*(cpyptr+lin1ofs  )>>4);
  348.         p[4]=(*(cpyptr+lin1ofs  )&0x0f);
  349.         p[5]=(*(cpyptr+lin1ofs+1)>>4);
  350.         p[6]=(*(cpyptr+lin2ofs  )>>4);
  351.         p[7]=(*(cpyptr+lin2ofs+1)&0x0f);
  352.         p[8]=(*(cpyptr+lin2ofs+1)>>4);
  353.         b=0;
  354.         for (i=0;i<9;i++) if (p[i]>b) b=p[i];
  355.       }
  356.     }
  357.     *(picptr++)=(b<<4)|15;
  358.     cpyptr+=1;
  359.     if (!(y%100))
  360.     { sprintf(&wtitel[0],"Verarbeite %03d %%",y*100/memheight);
  361.       SetWindowTitles(win,&wtitel[0],(UBYTE *)-1);
  362.     }
  363.   }
  364.   for (cnt=0;cnt<(memwidth>>1);cnt++) *(picptr++)=255;
  365.   SetWindowTitles(win," ",(UBYTE *)-1);
  366. }
  367.  
  368. static void sort(UBYTE *p,UBYTE n)
  369. { UBYTE f,i,t;
  370.  
  371.   do {
  372.     f=0;
  373.     for (i=0;i<(n-1);i++)
  374.       if (*(p+i) > *(p+i+1))
  375.       { t=*(p+i+1); *(p+i+1)=*(p+i); *(p+i)=t; f=1;}
  376.   } while (f);
  377. }
  378.  
  379. void median(void)
  380. { UBYTE *picptr,*cpyptr;
  381.   ULONG x,y,cnt;
  382.   ULONG lin1ofs,lin2ofs;
  383.  
  384.   UBYTE b,p[9];
  385.   char wtitel[64];
  386.  
  387.   SetWindowTitles(win,"Bewege",(UBYTE *)-1);
  388.   picptr=memptr+memneed;
  389.   cpyptr=picptr+(ULONG)(memwidth*2);
  390.   for (cnt=0;cnt<memneed;cnt++)
  391.     *(--cpyptr)=*(--picptr);
  392.   picptr=memptr;
  393.   cpyptr=picptr+(ULONG)(memwidth*2);
  394.   for (cnt=0;cnt<(memwidth>>1);cnt++) *(picptr++)=255;
  395.   lin1ofs=memwidth>>1;
  396.   lin2ofs=memwidth;
  397.   SetWindowTitles(win,"Verarbeite 000%",(UBYTE *)-1);
  398.   for (y=1;y<memheight-1;y++)
  399.   { b=15;
  400.     for (x=1;x<memwidth-1;x++)
  401.     { if (x&1)
  402.       { p[0]=(*(cpyptr          )&0x0f);
  403.         p[1]=(*(cpyptr+        1)>>4);
  404.         p[2]=(*(cpyptr+        1)&0x0f);
  405.         p[3]=(*(cpyptr+lin1ofs  )&0x0f);
  406.         p[4]=(*(cpyptr+lin1ofs+1)>>4);
  407.         p[5]=(*(cpyptr+lin1ofs+1)&0x0f);
  408.         p[6]=(*(cpyptr+lin2ofs  )&0x0f);
  409.         p[7]=(*(cpyptr+lin2ofs+1)>>4);
  410.         p[8]=(*(cpyptr+lin2ofs+1)&0x0f);
  411.         sort(p,9);
  412.         *(picptr++)=(b<<4)|p[4];
  413.         cpyptr++;
  414.       }
  415.       else
  416.       { p[0]=(*(cpyptr          )>>4);
  417.         p[1]=(*(cpyptr          )&0x0f);
  418.         p[2]=(*(cpyptr+        1)>>4);
  419.         p[3]=(*(cpyptr+lin1ofs  )>>4);
  420.         p[4]=(*(cpyptr+lin1ofs  )&0x0f);
  421.         p[5]=(*(cpyptr+lin1ofs+1)>>4);
  422.         p[6]=(*(cpyptr+lin2ofs  )>>4);
  423.         p[7]=(*(cpyptr+lin2ofs  )&0x0f);
  424.         p[8]=(*(cpyptr+lin2ofs+1)>>4);
  425.         sort(p,9);
  426.         b=p[4];
  427.       }
  428.     }
  429.     *(picptr++)=(b<<4)|15;
  430.     cpyptr+=1;
  431.     if (!(y%30))
  432.     { sprintf(&wtitel[0],"Verarbeite %03d %%",y*100/memheight);
  433.       SetWindowTitles(win,&wtitel[0],(UBYTE *)-1);
  434.     }
  435.   }
  436.   for (cnt=0;cnt<(memwidth>>1);cnt++) *(picptr++)=255;
  437.   SetWindowTitles(win," ",(UBYTE *)-1);
  438. }
  439.